#include "IApp.hpp"

namespace CEng {

	IApp::IApp(const std::string theTitle) :
		mTitle(theTitle),
		mRunning(false),
		mHeight(600),
		mWidth(800) {
	}
	
	IApp::~IApp() {
		mRunning = false;
	}
	
	void IApp::Run(void) {
		sf::Event event;
		mRunning = true;		

		mWindow.create(sf::VideoMode(mWidth, mHeight), mTitle);
		mWindow.display();
		
		while (mWindow.isOpen())
		{
			while (mWindow.pollEvent(event))
			{
				switch (event.type) {
					case sf::Event::Closed:
						mWindow.close();
						break;
					default:
						break;
				}
			}
        }
	}
	
	void IApp::AddTexture(const std::string thePath, const std::string theKey) {
		sf::Texture tempTexture;
		
		if (!tempTexture.loadFromFile(thePath)) {
			return;
		}
		
		mTextures.insert(std::pair<std::string, sf::Texture>(theKey, tempTexture));
	}
	
	void IApp::AddSprite(sf::IntRect theIntRect, const std::string theTextureKey, const std::string theSpriteKey) {
		sf::Sprite tempSprite;
		
		tempSprite.setTexture(mTextures[theTextureKey]);
		tempSprite.setTextureRect(theIntRect);
		
		mSprites.insert(std::pair<std::string, sf::Sprite>(theSpriteKey, tempSprite));
	}
	
	void IApp::EditSprite(float xpos, float ypos, std::string theSpriteKey) {		
		mSprites[theSpriteKey].setPosition(xpos, ypos);
	}
	
	sf::Texture IApp::GetTexture(const std::string theKey) {
		return mTextures[theKey];
	}
	
	sf::Sprite IApp::GetSprite(const std::string theKey) {
		return mSprites[theKey];
	}
	
}